#ifndef RPC_SOCKET_OPT_H_
#define RPC_SOCKET_OPT_H_

#include "base/base.h"

namespace rpc {
class Buffer;
class Socket;
struct Addr;
}

namespace sock {
int32 CreateSocket();
void Close(int sockfd);

bool Bind(rpc::Socket* s, const rpc::Addr& addr);
bool Listen(rpc::Socket* s);
int32 Accept(rpc::Socket* s, rpc::Addr* addr);

bool Connect(rpc::Socket* s, const rpc::Addr& addr);

bool GetSockOpt(rpc::Socket* s, int32 level, int32 opt, void* val,
                uint32* len);
bool SetSockOpt(rpc::Socket* s, int32 level, int32 opt, void* val, size_t len);
bool TrunOnOpt(rpc::Socket* s, int32 level, int32 opt);
bool TrunOffOpt(rpc::Socket* s, int32 level, int32 opt);

rpc::Addr GetSockAddr(rpc::Socket* s, bool is_local = true);

ssize_t Recv(const rpc::Socket* sock, rpc::Buffer* buf, size_t len);
ssize_t Recv(const rpc::Socket* sock, u_char* buf, size_t buflen);

ssize_t Send(const rpc::Socket* sock, rpc::Buffer* buf);
ssize_t Send(const rpc::Socket* sock, rpc::Buffer* buf, size_t len);
ssize_t Send(const rpc::Socket* sock, const u_char* buf, size_t buflen);

}

#endif
